package ar.frba.utn.diseñosistemas.Tests;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import junit.framework.Assert;

import ar.frba.utn.diseñosistemas.TP.*;
import org.junit.Before;
import org.junit.Test;

public class TestSimpleParser {
	
	SimpleParser Latinoamericano;
	SimpleParser Norteamericano;
	SimpleParser ISO8601;
	
	@Before
	public void setUp() throws Exception 
	{
		Latinoamericano = new SimpleParser(new SimpleDateFormat("dd/MM/yyyy"));
		Norteamericano = new SimpleParser(new SimpleDateFormat("MM-dd-yyyy"));		
		ISO8601 = new SimpleParser(new SimpleDateFormat("yyyy-MM-dd"));
	}
	
	@Test
	public void TestAssertFormatoLatinoamericano() throws Exception
	{
		UnifiedDate aDate = Latinoamericano.Parse("02/11/1989");
		
		Assert.assertTrue(aDate.getDay() == 2);
		Assert.assertTrue(aDate.getMonth() == 11 - 1); //Los meses en java van de 0 a 11
		Assert.assertTrue(aDate.getYear() == 1989);
	}
	
	@Test(expected = ParseException.class)
	public void TestParsearFechaNorteamericanaALatinoamericano() throws Exception
	{
		Latinoamericano.Parse("11-02-1989");
	}
	
	@Test(expected = ParseException.class)
	public void TestParsearFechaISOALatinoamericano() throws Exception
	{
		Latinoamericano.Parse("1989-11-02");
	}
	
	@Test
	public void TestAssertFormatoNorteamericano() throws Exception
	{
		UnifiedDate aDate = Norteamericano.Parse("11-02-1989");
		
		Assert.assertTrue(aDate.getDay() == 2);
		Assert.assertTrue(aDate.getMonth() == 11 - 1); //Los meses en java van de 0 a 11
		Assert.assertTrue(aDate.getYear() == 1989);
	}
	
	@Test(expected = ParseException.class)
	public void TestParsearFechaLatinoamericanaANorteamericano() throws Exception
	{
		Norteamericano.Parse("02/11/1989");
	}
	
	@Test(expected = ParseException.class)
	public void TestParsearFechaISOANorteamericano() throws Exception
	{
		Norteamericano.Parse("1989-11-02");
	}
	
	@Test
	public void TestAssertFormatoISO8601() throws Exception
	{
		UnifiedDate aDate = ISO8601.Parse("1989-11-02");
		
		Assert.assertTrue(aDate.getDay() == 2);
		Assert.assertTrue(aDate.getMonth() == 11 - 1); //Los meses en java van de 0 a 11
		Assert.assertTrue(aDate.getYear() == 1989);
	}
	
	@Test(expected = ParseException.class)
	public void TestParsearFechaLatinoamericanaISO8601() throws Exception
	{
		ISO8601.Parse("02/11/1989");
	}
	
	@Test(expected = ParseException.class)
	public void TestParsearFechaNorteamericanaAISO8601() throws Exception
	{
		ISO8601.Parse("11-02-1989");
	}
}
